<template>
  <div class="graph_container">
    <FifKnowledgeGraph v-if="graphConfig.graphId" :graphConfig=graphConfig></FifKnowledgeGraph>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue"
import { Getway } from "fif-utils"
// 实例化网关
const getway = new Getway({
  appCode: 'adopt',
  tokenKey: "test-token",
  baseUrl: 'https://apics.fifedu.com/',
  timeout: 5000,
  isLog: false,
  toLogin: async () => {
    // 未登录
    window.location.replace(`${'https://hecs.fifedu.com'}/iplat/fifLogin/index.html?service=${encodeURIComponent(window.location.href)}`)
  }
})

let graphConfig = ref({
  graphId: ''
})

onMounted(async () => {
  // 通过网关创建Axios
  const GETWAY = await getway.createAxios()

  // 解决data返回值问题，如果项目已有，不用配置
  GETWAY.Axios.interceptors.response.use(function (response) {
    let data = response.data
    if (response.status == 200 && data.status == 1) {
      return data
    }
  }, function (error) {
    return Promise.reject(error || 'Error')
  })

  let userInfo = {
    schoolId: '2811000226000001210',
  }
  graphConfig.value = {
    graphId: 'c07f7f7d53c2488fac48eeb827a1f691', //图谱id 必填
    courseId: '', // 课程id
    compile: 0, // 0可以编辑，1无权限编辑
    page: null, // iframe= 隐藏返回、切换课程、绑定课程、分享共建、保存状态
    hidePreview: 0, // 隐藏图谱预览 1=隐藏
    userInfo: userInfo, // npm组件必传
    getway: GETWAY // 网关实例 如果项目已经接入网关，直接传入即可 必填
  }
})


</script>

<style scoped>
.graph_container {
  width: 100%;
  height: 600px;
}

.graph_container>>>.container {
  height: 100%;
}
</style>
